{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# FAQ"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "安装第三方库时，出现 “python version 2.7 required which was not found in the registry”类似信息，可以尝试执行下面脚本"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "#\n",
    "# script to register Python 2.0 or later for use with win32all\n",
    "# and other extensions that require Python registry settings\n",
    "#\n",
    "# written by Joakim Loew for Secret Labs AB / PythonWare\n",
    "#\n",
    "# source:\n",
    "# http://www.pythonware.com/products/works/articles/regpy20.htm\n",
    "#\n",
    "# modified by Valentine Gogichashvili as described in http://www.mail-archive.com/distutils-sig@python.org/msg10512.html\n",
    " \n",
    "import sys\n",
    " \n",
    "from _winreg import *\n",
    " \n",
    "# tweak as necessary\n",
    "version = sys.version[:3]\n",
    "installpath = sys.prefix\n",
    " \n",
    "regpath = \"SOFTWARE\\\\Python\\\\Pythoncore\\\\%s\\\\\" % (version)\n",
    "installkey = \"InstallPath\"\n",
    "pythonkey = \"PythonPath\"\n",
    "pythonpath = \"%s;%s\\\\Lib\\\\;%s\\\\DLLs\\\\\" % (\n",
    "    installpath, installpath, installpath\n",
    ")\n",
    " \n",
    "def RegisterPy():\n",
    "    try:\n",
    "        reg = OpenKey(HKEY_CURRENT_USER, regpath)\n",
    "    except EnvironmentError as e:\n",
    "        try:\n",
    "            reg = CreateKey(HKEY_CURRENT_USER, regpath)\n",
    "            SetValue(reg, installkey, REG_SZ, installpath)\n",
    "            SetValue(reg, pythonkey, REG_SZ, pythonpath)\n",
    "            CloseKey(reg)\n",
    "        except:\n",
    "            print \"*** Unable to register!\"\n",
    "            return\n",
    "        print \"--- Python\", version, \"is now registered!\"\n",
    "        return\n",
    "    if (QueryValue(reg, installkey) == installpath and\n",
    "        QueryValue(reg, pythonkey) == pythonpath):\n",
    "        CloseKey(reg)\n",
    "        print \"=== Python\", version, \"is already registered!\"\n",
    "        return\n",
    "    CloseKey(reg)\n",
    "    print \"*** Unable to register!\"\n",
    "    print \"*** You probably have another Python installation!\"\n",
    " \n",
    "if __name__ == \"__main__\":\n",
    "    RegisterPy()"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 2",
   "language": "python",
   "name": "python2"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.11"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
